package edu.ccut.saturn.studio.core.util.log.listener;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import edu.ccut.saturn.studio.core.util.log.ILoggerListener;

/**
 * 采用了log4j技术实现了ILoggerListener定义的日志操作的接口
 * 
 * @author 温建
 * 
 * @version 1.0 2008.09.09
 *
 */
public class Log4jLoggerListener implements ILoggerListener {

	public Log4jLoggerListener() {
	}
	
	public void debug(String key, String message, Throwable throwable) {
		this.getLogger(key).debug(message, throwable);
	}

	public void debug(String key, String message) {
		this.getLogger(key).debug(message);
	}

	public void error(String key, String message, Throwable throwable) {
		this.getLogger(key).error(message, throwable);
	}

	public void error(String key, String message) {
		this.getLogger(key).error(message);
	}

	public void fatal(String key, String message, Throwable throwable) {
		this.getLogger(key).fatal(message, throwable);
	}
	
	public void fatal(String key, String message) {
		this.getLogger(key).fatal(message);		
	}

	public String getLevel(String key) {
		return this.getLogger(key).getLevel().toString();
	}

	public void info(String key, String message) {
		this.getLogger(key).info(message);
	}

	public void info(String key, String message, Throwable throwable) {
		this.getLogger(key).info(message, throwable);
	}

	public void setLevel(String key, String level) {
		this.getLogger(key).setLevel(Level.toLevel(level));
	}

	public void warn(String key, String message, Throwable throwable) {
		this.getLogger(key).warn(message, throwable);
	}

	public void warn(String key, String message) {
		this.getLogger(key).warn(message);
	}
	
	private Logger getLogger(String key) {
		if (key != null) {
			return Logger.getLogger(key);
		}
		
		return Logger.getRootLogger();
	}
}

